package com.example.security.config;

import com.example.security.service.UserService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DataInitializer {

    @Autowired
    private UserService userService;

    @PostConstruct
    public void initializeData() {
        try {
            // 创建一个普通用户
            userService.registerUser("user", "password", "user@example.com");
            
            // 创建一个管理员用户
            userService.registerAdmin("admin", "admin", "admin@example.com");
            
            System.out.println("数据初始化完成！");
        } catch (Exception e) {
            System.out.println("数据已存在，跳过初始化: " + e.getMessage());
        }
    }
} 